package com.patni.body.detail;

import java.awt.Graphics;
import java.awt.Image;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ImageLabel extends JLabel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

public ImageLabel(String path){
	JLabel image =new ImageL(path);
	image.setBorder(BorderFactory.createEtchedBorder());
	this.setLayout(null);
	this.add(image);
	this.setBounds(0, 0, Module.moduleHeight, Module.moduleHeight);
}

public static void main(String[] args){
	JFrame j=new JFrame("!!!");
	j.setLayout(null);
	
	ImageLabel l=new ImageLabel("1.jpg");
	j.add(l);
	j.setBounds(100, 100, 200, 200);
	j.setVisible(true);
}

}
class ImageL extends JLabel{

	private static final long serialVersionUID = 1L;
	private Image icon;
	private String path;
public ImageL(String path){
	this.path=path;
//	icon=this.getToolkit().getImage(path);
	icon=new ImageIcon(path).getImage().getScaledInstance(42, 42, 0);
	this.setBounds(7, 7, 42, 42);
	r();	
}

@Override
protected void paintComponent(Graphics g) {
	// TODO Auto-generated method stub
	super.paintComponent(g);	
	g.drawImage(icon, 0, 0,null);
	
//	System.out.println("刷新。。。");
}

public void r(){
	new Timer().schedule(new TimerTask(){
		@Override
		public void run() {
			// TODO Auto-generated method stub
			repaint();
		}
		
	}, 100);
}
}
